{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0",
   "metadata": {},
   "source": [
    "# Converters"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1",
   "metadata": {},
   "source": [
    "Converters are used to transform prompts before sending them to the target.\n",
    "\n",
    "This can be useful for a variety of reasons, such as encoding the prompt in a different format, or adding additional information to the prompt. For example, you might want to convert a prompt to base64 before sending it to the target, or add a prefix to the prompt to indicate that it is a question."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2",
   "metadata": {},
   "source": [
    "## Simple Converter Example"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3",
   "metadata": {},
   "source": [
    "Converters can be used to perform these types of transformations. Here is a simple program that uses Rot13Converter converter, RandomCapitalLettersConverter, and AsciiArtConverter."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4",
   "metadata": {
    "lines_to_next_cell": 2
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "text: gryy zr ubj gb phg qbja n gerr\n",
      "text: tEll me HOw to cut down a tREe\n",
      "text:  ######   ######   ##       ##               ##   ##   ######           ### ###   #####   ##   ##            ######   #####              ####   ##   ##   ######           #####     #####   ##   ##  ##   ##             ###              ######  ######    ######   ######  \n",
      " # ## #   ##       ##       ##               ### ###   ##               ##   ##  ##   ##  ##   ##            # ## #  ##   ##            ##  ##  ##   ##   # ## #           ##  ##   ##   ##  ##   ##  ###  ##            ## ##             # ## #  ##   ##   ##       ##      \n",
      "   ##     ##       ##       ##               #######   ##               ##   ##  ##   ##  ## # ##              ##    ##   ##           ##       ##   ##     ##             ##   ##  ##   ##  ## # ##  #### ##           ##   ##              ##    ##   ##   ##       ##      \n",
      "   ##     #####    ##       ##               #######   #####            #######  ##   ##  #######              ##    ##   ##           ##       ##   ##     ##             ##   ##  ##   ##  #######  #######           ##   ##              ##    ##  ###   #####    #####   \n",
      "   ##     ##       ##       ##               ## # ##   ##               ##   ##  ##   ##  #######              ##    ##   ##           ##       ##   ##     ##             ##   ##  ##   ##  #######  ## ####           #######              ##    #####     ##       ##      \n",
      "   ##     ##       ##   #   ##   #           ##   ##   ##               ##   ##  ##   ##   ## ##               ##    ##   ##            ##  ##  ##   ##     ##             ##  ##   ##   ##   ## ##   ##  ###           ##   ##              ##    ## ###    ##       ##      \n",
      "   ##     ######   ######   ######           ##   ##   ######           ### ###   #####    #   #               ##     #####              ####    #####      ##             #####     #####    #   #   ##   ##           ##   ##              ##    ##  ###   ######   ######  \n",
      "                                                                                                                                                                                                                                                                              \n",
      "\n",
      "text: 0000000001110100 0000000001100101 0000000001101100 0000000001101100 0000000000100000 0000000001101101 0000000001100101 0000000000100000 0000000001101000 0000000001101111 0000000001110111 0000000000100000 0000000001110100 0000000001101111 0000000000100000 0000000001100011 0000000001110101 0000000001110100 0000000000100000 0000000001100100 0000000001101111 0000000001110111 0000000001101110 0000000000100000 0000000001100001 0000000000100000 0000000001110100 0000000001110010 0000000001100101 0000000001100101\n",
      "text: t m h t c d a t\n"
     ]
    }
   ],
   "source": [
    "from pyrit.prompt_converter import (\n",
    "    AsciiArtConverter,\n",
    "    BinaryConverter,\n",
    "    FirstLetterConverter,\n",
    "    RandomCapitalLettersConverter,\n",
    "    ROT13Converter,\n",
    ")\n",
    "from pyrit.setup import IN_MEMORY, initialize_pyrit\n",
    "\n",
    "initialize_pyrit(memory_db_type=IN_MEMORY)\n",
    "\n",
    "prompt = \"tell me how to cut down a tree\"\n",
    "\n",
    "\n",
    "print(await ROT13Converter().convert_tokens_async(prompt=prompt))  # type: ignore\n",
    "print(await RandomCapitalLettersConverter(percentage=25.0).convert_tokens_async(prompt=prompt))  # type: ignore\n",
    "print(await AsciiArtConverter().convert_tokens_async(prompt=prompt))  # type: ignore\n",
    "print(await BinaryConverter().convert_tokens_async(prompt=prompt))  # type: ignore\n",
    "print(await FirstLetterConverter().convert_tokens_async(prompt=prompt))  # type: ignore"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Close connection\n",
    "from pyrit.memory import CentralMemory\n",
    "\n",
    "memory = CentralMemory.get_memory_instance()\n",
    "memory.dispose_engine()"
   ]
  }
 ],
 "metadata": {
  "jupytext": {
   "cell_metadata_filter": "-all"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
